<template>
  <!-- 添加或修改通用机械试验对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="检验编号" prop="inspectNumber">
                <el-input v-model="form.inspectNumber" placeholder="请输入检验编号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原材料制造商" prop="producer">
                <el-input v-model="form.producer" placeholder="请输入原材料制造商"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="牌号" prop="code">
                <el-input v-model="form.code" placeholder="请输入牌号"/>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="来料检验批次号" prop="batchNumber">
                <el-input v-model="form.batchNumber" placeholder="请输入来料检验批次号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检测日期" prop="inspectDate">
                <el-date-picker clearable
                                v-model="form.inspectDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择检测日期">
                </el-date-picker>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="机械性能-抗拉强度" prop="tensileStrength">
                <el-input v-model="form.tensileStrength" placeholder="请输入机械性能-抗拉强度"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="屈服强度" prop="succumbStrength">
                <el-input v-model="form.succumbStrength" placeholder="请输入屈服强度"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="机械性能-断后伸长率" prop="extend">
                <el-input v-model="form.extend" placeholder="请输入机械性能-断后伸长率"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="机械性能-硬度" prop="hardness">
                <el-input v-model="form.hardness" placeholder="请输入机械性能-硬度"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="拉伸强度" prop="pullStrength">
                <el-input v-model="form.pullStrength" placeholder="请输入拉伸强度"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="延伸率" prop="extendRate">
                <el-input v-model="form.extendRate" placeholder="请输入延伸率"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="力学性能-单丝强度" prop="singleStrength">
                <el-input v-model="form.singleStrength" placeholder="请输入力学性能-单丝强度"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="质检是否通过" prop="testPass">
                <el-input v-model="form.testPass" placeholder="请输入质检是否通过"/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="检测结果" prop="result">
                <el-input v-model="form.result" type="textarea" placeholder="请输入内容"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "FactoryTestMachineryCommonForm",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      url: {
        getById: '/factoryTestMachineryCommon/factoryTestMachineryCommon/',
        add: '/factoryTestMachineryCommon/factoryTestMachineryCommon/add',
        edit: '/factoryTestMachineryCommon/factoryTestMachineryCommon/edit',
      },
    };
  },
  created() {

  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectId: null,
        projectCode: null,
        orderId: null,
        workOrderId: null,
        workOrderCode: null,
        materialId: null,
        goodsId: null,
        daohuoDetailId: null,
        rukuId: null,
        produceRecordDetailId: null,
        fahuoDetailId: null,
        sampleId: null,
        goodsCode: null,
        orderCode: null,
        goodsSaleId: null,
        name: null,
        inspectNumber: null,
        type: null,
        producer: null,
        code: null,
        heatBatchNumber: null,
        batchNumber: null,
        leaveInspectDate: null,
        arriveInspectDate: null,
        tensileStrength: null,
        succumbStrength: null,
        extend: null,
        hardness: null,
        pullStrength: null,
        extendRate: null,
        singleStrength: null,
        testPass: null,
        result: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加通用机械试验";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改通用机械试验";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
  }
};
</script>
